home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------
- // MetafilePageUnits.cs ⌐ 2001 by Charles Petzold
- //------------------------------------------------
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Printing; // íYa no se usa!
- using System.Windows.Forms;
-
- class MetafilePageUnits: PrintableForm
- {
- Metafile mf;
-
- public new static void Main()
- {
- Application.Run(new MetafilePageUnits());
- }
- public MetafilePageUnits()
- {
- Text = "Unidades de pßgina en metarchivos";
-
- // Crear el metarchivo.
-
- Graphics grfx = CreateGraphics();
- IntPtr ipHdc = grfx.GetHdc();
-
- mf = new Metafile("MetafilePageUnits.emf", ipHdc);
-
- grfx.ReleaseHdc(ipHdc);
- grfx.Dispose();
-
- // Obtener el objeto Graphics para dibujar sobre el metarchivo.
-
- grfx = Graphics.FromImage(mf);
- grfx.Clear(Color.White);
-
- // Dibujar en unidades de pφxeles (lßpiz de 1 punto de grosor).
-
- grfx.PageUnit = GraphicsUnit.Pixel;
- Pen pen = new Pen(Color.Black, grfx.DpiX / 72);
- grfx.DrawRectangle(pen, 0, 0, grfx.DpiX, grfx.DpiY);
-
- // Dibujar en unidades de 1/100 pulgadas (lßpiz de 1 punto de grosor).
-
- grfx.PageUnit = GraphicsUnit.Inch;
- grfx.PageScale = 0.01f;
- pen = new Pen(Color.Black, 100f / 72);
- grfx.DrawRectangle(pen, 25, 25, 100, 100);
-
- // Dibujar en unidades de milφmetros (lßpiz de 1 punto de grosor).
-
- grfx.PageUnit = GraphicsUnit.Millimeter;
- grfx.PageScale = 1;
- pen = new Pen(Color.Black, 25.4f / 72);
- grfx.DrawRectangle(pen, 12.7f, 12.7f, 25.4f, 25.4f);
-
- // Dibujar en unidades de puntos (lßpiz de 1 punto de grosor).
-
- grfx.PageUnit = GraphicsUnit.Point;
- pen = new Pen(Color.Black, 1);
- grfx.DrawRectangle(pen, 54, 54, 72, 72);
-
- grfx.Dispose();
- }
- protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
- {
- grfx.DrawImage(mf, 0, 0);
- }
- }
-